<?php
class DangkiesController extends AppController {

	var $name = 'Dangkies';
	var $helpers = array('Html', 'Form');

	function index() {
		$this->Dangky->recursive = 0;
		$this->set('dangkies', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid Dangky', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('dangky', $this->Dangky->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Dangky->create();
			if ($this->Dangky->save($this->data)) {
				$this->Session->setFlash(__('The Dangky has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The Dangky could not be saved. Please, try again.', true));
			}
		}
		$sinhviens = $this->Dangky->Sinhvien->find('list');
		$nhomths = $this->Dangky->Nhomth->find('list');
		$this->set(compact('sinhviens', 'nhomths'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid Dangky', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Dangky->save($this->data)) {
				$this->Session->setFlash(__('The Dangky has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The Dangky could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Dangky->read(null, $id);
		}
		$sinhviens = $this->Dangky->Sinhvien->find('list');
		$nhomths = $this->Dangky->Nhomth->find('list');
		$this->set(compact('sinhviens','nhomths'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for Dangky', true));
			$this->redirect(array('action' => 'index'));
		}
		if ($this->Dangky->del($id)) {
			$this->Session->setFlash(__('Dangky deleted', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->Session->setFlash(__('The Dangky could not be deleted. Please, try again.', true));
		$this->redirect(array('action' => 'index'));
	}

}
?>